import os
from google.appengine.ext.webapp import template

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


import logging

from views.login import *
from views.TopicController import *
from views.GroupController import *
from views.AuditController import *
from views.ImageHandler import *
from views.ProfileController import *
from views.MessageController import *
from views.Registration import *
from views.SuperUserController import *
from views.UserController import * 
# for attr in ('stdin', 'stdout', 'stderr'):
#     setattr(sys, attr, getattr(sys, '__%s__' % attr))
# import pdb
# pdb.set_trace()
# logging.debug(str(sys.path))
#sys.path.append("/Users/Ryan/Documents/Computer Programs/CSE 110/Python_version/public")


webapp.template.register_template_library('templatetags.userinfo')


"""
This is the URL handling. You can use regexes for the urls to match on.
Second parameter is the View to run. Views are located in /views/. Dont forget to 
import the file that the view you want is located in.
"""
application = webapp.WSGIApplication([
                                       ('/', ViewGroups), ('/register', Registration), ("/login", Login),
                                       ("/logout", Logout),
                                       ('/topic/(.+)[/]?$',ViewMessagesByTopic),
                                       ('/group/(.+)[/]?$',ViewTopicsByGroup),
                                       ('/newmessage/(.*)[/]?$',NewMessage),
                                       ('/newtopic/(.*)[/]?$',NewTopic),
                                       ('/message/(.*)[/]?$',ViewMessage),
                                       ('/deletemessage/(.*)[/]?',DeleteMessage),
                                       ('/modifymessage/(.*)[/]?',ModifyMessage),
                                       ('/newreply/(.*)[/]?$',NewReply),
                                       ('/newgroup[/]?$',NewGroup),
                                       ('/modifygroup/(.*)[/]?',ModifyGroup),
                                       ('/deletegroup/(.*)[/]?',DeleteGroup),
                                       ('/group[/]?$',ViewGroups),
                                       ('/deletetopic/(.*)[/]?',DeleteTopic),
                                       ('/modifytopic/(.*)[/]?',ModifyTopic),
                                       ('/important/(.*)[/]?',ModifyImportant),
                                       ('/modifyread/(.*)/(.*)[/]?',ModifyRead),
                                       ('/viewaudit[/]?',ViewAudit),
                                       ('/img',Image),
                                       ('/profileimg/(.*)[/]?',ProfileImage),
                                       ('/customize/(.*)[/]?',CustomizeProfile),
                                       ('/viewprofile/(.*)[/]?',ViewProfile),
("/moderators", AddNewModerators),
("/userinfo",UserInfo),
                                     ], debug=True)

def main():
  # Start the main site
  run_wsgi_app(application)
  
if __name__ == "__main__":
  main()
